package com.xxxx;

import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.configuration.Configuration;

/**
 * 批量数据处理
 */
public class Hello13FlinkRichMap {
    public static void main(String[] args) throws Exception {
        //创建环境
        ExecutionEnvironment environment = ExecutionEnvironment.getExecutionEnvironment();
        //获取数据源
        DataSource<Integer> source = environment.fromElements(1, 2, 3, 4, 5, 6, 7);
        //过滤
        source.map(new RichMapFunction<Integer, String>() {

            String pid = null;


            @Override
            public void open(Configuration parameters) throws Exception {
                pid = "goodStudy" + Math.random() + ":";
            }

            @Override
            public void close() throws Exception {
                pid = null;
            }

            @Override
            public String map(Integer integer) throws Exception {
                return pid + integer + "--" + getRuntimeContext().getIndexOfThisSubtask();
            }
        }).print();

    }
}
